package com.gitee.ed.arithmetic.leetcode.question.question_1_100.question_1_10;

import com.gitee.ed.arithmetic.leetcode.SolutionRunner;
import com.gitee.ed.arithmetic.leetcode.solution.solution_1_100.solution_1_10.Solution2;
import com.gitee.ed.arithmetic.leetcode.common.Question;
import com.gitee.ed.arithmetic.leetcode.struct.ListNode;

/**
 * @author hongda.li
 */
public class Question2 implements Question<Solution2> {
    @Override
    public String link() {
        return "https://leetcode.cn/problems/add-two-numbers/description/";
    }

    @Override
    public String title() {
        return "2.两数相加";
    }

    @Override
    public String description() {
        return """
                给你两个非空的链表，表示两个非负的整数。它们每位数字都是按照逆序的方式存储的，并且每个节点只能存储一位数字。
                请你将两个数相加，并以相同形式返回一个表示和的链表。
                你可以假设除了数字 0 之外，这两个数都不会以 0 开头。
                """;
    }

    @Override
    public void test(Solution2 solution) {
        this.test1(solution);

        this.test2(solution);

        this.test3(solution);
    }

    private void test1(Solution2 solution) {
        ListNode node1 = ListNode.from(2, 4, 3);
        ListNode node2 = ListNode.from(5, 6, 4);

        ListNode expect = ListNode.from(7, 0, 8);
        ListNode actual = solution.addTwoNumbers(node1, node2);

        SolutionRunner.checkString(expect, actual);
    }

    private void test2(Solution2 solution) {
        ListNode node1 = ListNode.from(0);
        ListNode node2 = ListNode.from(0);

        ListNode expect = ListNode.from(0);
        ListNode actual = solution.addTwoNumbers(node1, node2);

        SolutionRunner.checkString(expect, actual);
    }

    private void test3(Solution2 solution) {
        ListNode node1 = ListNode.from(9, 9, 9, 9, 9, 9, 9);
        ListNode node2 = ListNode.from(9, 9, 9, 9);

        ListNode expect = ListNode.from(8, 9, 9, 9, 0, 0, 0, 1);
        ListNode actual = solution.addTwoNumbers(node1, node2);

        SolutionRunner.checkString(expect, actual);
    }
}
